package com.fairytask.ui
{
	import com.fairytask.engine.GameStage;
	import com.fairytask.engine.managers.ResManager;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	/**
	 * 后台消息请求等待提示UI 
	 * @author zhuy
	 * 
	 */	
	public class AskMsgWaitUI extends Sprite
	{
		private static var _self	:AskMsgWaitUI;
		public var bg_mc       	:Sprite;	//透明层
		public  var res			:MovieClip;	//load
		private var _time      	:Timer;
		
		public static function getInstance():AskMsgWaitUI
		{
			if(_self == null)
			{
				_self	=	new AskMsgWaitUI();				
			}
			return _self;
		}
		
		public function AskMsgWaitUI()
		{
			init();
			initEvent();
		}
		
		private function init():void
		{
			_time = new Timer(5000,1);
			bg_mc = new Sprite();
			res   = ResManager.newResClass("loadPie") as MovieClip;
			addChild(bg_mc);
			addChild(res);
		}
		
		private function initEvent():void
		{
			_time.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
		}
		
		private function timerHandler(evt:TimerEvent):void
		{
			hide();
		}

		public function onShow(_x:Number,_y:Number,_width:Number,_height:Number,_parent:Sprite = null):void
		{
			bg_mc.graphics.beginFill(0x0066CC,0.2);
			bg_mc.graphics.drawRect(_x,_y,_width,_height);
			bg_mc.graphics.endFill();
			res.x = _x + (bg_mc.width - res.width)/2;
			res.y = _y + (bg_mc.height - res.height)/2;
			if(null == _parent)
			{
				GameStage.uiSpace.addLoad(this);
			}else
			{
				_parent.addChild(this);
			}
			_time.reset();
			_time.start();
		}
		
		public function hide():void
		{
			bg_mc.graphics.clear();
			if(this.parent)
			{
				this.parent.removeChild(this);
			}
		}
	}
}